package com.atguigu.tingshu.user.config.wechat.login;

import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl;
import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl;
import jakarta.annotation.Resource;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

/**
 * 微信小程序配置
 * @author Haoran Sun
 * @since 2024/08/16
 */

@Component
public class WeChatConfig {

    @Resource
    private WeChatLoginConfig weChatLoginConfig;

    /**
     * 微信小程序服务
     * @return 微信小程序服务
     */
    @Bean
    public WxMaService wxMaService(){
        WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl();
        config.setAppid(weChatLoginConfig.getAppId());
        config.setSecret(weChatLoginConfig.getAppSecret());
        config.setMsgDataFormat("json");
        WxMaServiceImpl service = new WxMaServiceImpl();
        service.setWxMaConfig(config);
        return service;
    }

}
